#ifndef _RD522_SPI_H
#define _RD522_SPI_H

#include "stm32f0xx.h"

#define W_FIFOADDR  (0x09 << 1) & 0x7E
#define R_FIFOADDR  ((0x09 << 1) & 0X7E) | 0x80	//fifo_reg:0x09

//ZKRD522 硬件SPI
#define       RD522_SPI                SPI1
#define       RD522_SPI_CLK            RCC_APB2Periph_SPI1

#define PIN_SPI1_CSN    GPIO_Pin_15
#define PIN_SPI1_SCK    GPIO_Pin_3
#define PIN_SPI1_MISO   GPIO_Pin_4
#define PIN_SPI1_MOSI   GPIO_Pin_5
   
#define	RD522_SPI_CS_LOW       GPIO_ResetBits(GPIOA, PIN_SPI1_CSN)
#define	RD522_SPI_CS_HIGH      GPIO_SetBits(GPIOA, PIN_SPI1_CSN)


void spi1_init(void);
void spi_write_reg(uint8_t addr, uint8_t value);
uint8_t  spi_read_reg(uint8_t addr);
void spi_read_fifo(uint8_t *val, uint8_t rec_len);
void spi_write_fifo(uint8_t *val, uint8_t send_len);
void spi_set_bit_mask(uint8_t reg, uint8_t mask);
void spi_clear_bit_mask(uint8_t reg, uint8_t mask);

#endif



